﻿<Controls:MetroWindow x:Class="WpfClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:nota="clr-namespace:NotaManager;assembly=NotaManager"
        xmlns:local="clr-namespace:WpfClient"
        xmlns:viewModels="clr-namespace:WpfClient.Models"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        Title="MainWindow" Height="550" Width="725"
                      
        GlowBrush="{DynamicResource AccentColorBrush}"
        WindowStartupLocation="CenterScreen"
                      >
    <Controls:MetroWindow.Resources>

        <!--<Style TargetType="Button" BasedOn="{StaticResource SquareButtonStyle}">
           
            
        </Style>-->

        <local:RatingToColorConverter x:Key="RatingToColor"></local:RatingToColorConverter>
        <local:NullToVisibilityConverter x:Key="NullConverter"></local:NullToVisibilityConverter>
        <local:InvertBoolConverter x:Key="InvertConverter"></local:InvertBoolConverter>

        <DataTemplate x:Key="LineTemplate" DataType="{x:Type viewModels:LineViewModel}">
            <Border BorderThickness="1" BorderBrush="Black" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Border Grid.Column="0"  BorderBrush="Black" BorderThickness="0 0 1 0">
                        <TextBlock 
                    MaxWidth="100" 
                    Margin="10 0 10 0"
                    Text="{Binding Number}"></TextBlock>
                    </Border>

                    <Border Grid.Column="1" Margin="0" Padding="0">
                        <StackPanel>
                            <TextBlock Text="{Binding Line.Eng}" FontWeight="Bold"></TextBlock>
                            <TextBlock Text="{Binding Line.Rus[0].Value}" FontSize="12"></TextBlock>
                        </StackPanel>
                    </Border>
                </Grid>
            </Border>

        </DataTemplate>

        <DataTemplate x:Key="FileTemplate" DataType="{x:Type viewModels:FileViewModel}">
            <StackPanel>
                <ContentControl>
                    <TextBlock Text="{Binding Title}"></TextBlock>
                </ContentControl>


            </StackPanel>
        </DataTemplate>

        <Style x:Key="FilesListStyle" TargetType="ListBox">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
            <Setter Property="VerticalAlignment" Value="Stretch"></Setter>


        </Style>

        <Style x:Key="InputTextBox" TargetType="{x:Type TextBox}">
            <Setter Property="Margin" Value="0 10"></Setter>
            <Setter Property="TextWrapping" Value="Wrap"></Setter>
            <Setter Property="Foreground" Value="Black"></Setter>
            <!--<Setter Property="IsEnabled" Value="False"></Setter>-->
            <Setter Property="IsReadOnly" Value="True"></Setter>
        </Style>

        <Style x:Key="Label" TargetType="{x:Type TextBlock}">
            <Setter Property="Margin" Value="0 10"></Setter>
            <Setter Property="FontWeight" Value="ExtraBold"></Setter>

        </Style>

        <DataTemplate x:Key="LineDetailsTemplate" DataType="{x:Type viewModels:LineViewModel}">
            <StackPanel>
                <TextBlock Text="Оригинал" Style="{StaticResource Label}"></TextBlock>
                <TextBox Text="{Binding Line.Eng}" Style="{StaticResource InputTextBox}" ></TextBox>
                <TextBox Text="{Binding Line.Jap}" Style="{StaticResource InputTextBox}" ></TextBox>

                <TextBlock Text="Варианты перевода" Style="{StaticResource Label}"></TextBlock>
                <ItemsControl
                    ItemsSource="{Binding Line.Rus}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"></ColumnDefinition>
                                    <ColumnDefinition Width="auto"></ColumnDefinition>
                                    <ColumnDefinition Width="*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>

                                <Border
                                     Grid.Column="0" 
                                    
                                   
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Margin="0 0 10 0"
                                    >
                                    <TextBlock 
                                   
                                    Foreground="{Binding Rating, Converter={StaticResource RatingToColor}}"
                                    Margin="2"
                                    FontWeight="Bold"
                                    Text="{Binding Rating}"
                                    ></TextBlock>

                                </Border>

                                <Button Grid.Column="1" 
                                        Width="100" Height="20" 
                                        
                                        Margin="0 0 10 0"
                                        
                                        Tag="{Binding Value}"
                                        Click="Button_Click_1"
                                        >Скопировать</Button>

                                <TextBox Grid.Column="2" Text="{Binding Value}" Style="{StaticResource InputTextBox}"></TextBox>
                            </Grid>


                        </DataTemplate>
                    </ItemsControl.ItemTemplate>

                </ItemsControl>
            </StackPanel>
        </DataTemplate>
        
    </Controls:MetroWindow.Resources>
   
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
        </Grid.RowDefinitions>

        <Menu Grid.Row="0">
            <MenuItem Header="Операции">
                <MenuItem Header="Обновить скрипт" Command="{Binding RefreshScript}"></MenuItem>
                <MenuItem Header="Синхронизация с новеллой" Command="{Binding StartNovel}" IsCheckable="True" IsChecked="{Binding InNovel}">
                </MenuItem>
                <MenuItem Header="Настройки" Command="{Binding UpdateSettings}"></MenuItem>
                <MenuItem Header="Выход"></MenuItem>
            </MenuItem>
            <MenuItem Header="Информация"></MenuItem>
        </Menu>
        
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <ListBox Grid.Column="0" 
                 ItemsSource="{Binding Files}" 
                 ItemTemplate="{StaticResource FileTemplate}"
                 Style="{StaticResource FilesListStyle}"
                 MinWidth="150"
                 Name="FilesBox"
                
                 >
            </ListBox>
            <Grid Grid.Column="1" Visibility="{Binding ElementName=FilesBox, Path=SelectedItem, Converter={StaticResource NullConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="*" ></RowDefinition>

                </Grid.RowDefinitions>
                <GridSplitter 
                Grid.Row="1" 
                VerticalAlignment="Center" 
                HorizontalAlignment="Stretch"
                Background="Gray"
                ShowsPreview="True" 
                Height="3"></GridSplitter>

                <ListBox 
                Grid.Row="0"
                Name="LinesList"
                ItemsSource="{Binding ElementName=FilesBox, Path=SelectedItem.Lines, Mode=TwoWay}"
                ItemTemplate="{StaticResource LineTemplate}"
                Style="{StaticResource FilesListStyle}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                SelectionChanged="LinesList_SelectionChanged"
                >

                </ListBox>
                <ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto">
                    <Border Padding="20">
                        <StackPanel>
                            <ContentControl
                        Name="Line"
                ContentTemplate="{StaticResource LineDetailsTemplate}"
                Content="{Binding ElementName=LinesList, Path=SelectedItem, Mode=TwoWay}"
                
                >
                            </ContentControl>

                            <TextBlock Text="Ваш новый перевод (хД)" Style="{StaticResource Label}" Name="InputStatusText"></TextBlock>
                            <TextBox 
                        Name="InputedText" 
                        Style="{StaticResource InputTextBox}" 
                        IsReadOnly="False" 
                       ></TextBox>

                            <Button Click="Button_Click" Name="PostButton">Post to Nota</Button>

                        </StackPanel>
                    </Border>
                </ScrollViewer>
            </Grid>
        </Grid>

        <StatusBar Grid.Row="2" >
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"></StackPanel>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem>
                <TextBlock Text="{Binding LastError}" TextWrapping="Wrap"></TextBlock>
            </StatusBarItem>
        </StatusBar>
        
    </Grid>
    
</Controls:MetroWindow>
